const gulp = require("gulp");
const {
  src,
  dest,
  watch,
  series,
  parallel
} = require("gulp");
const concat = require("gulp-concat");
const connect = require("gulp-connect");
const uglify = require("gulp-uglify");
const rename = require("gulp-rename");
const babel = require("gulp-babel");
const proxy = require("http-proxy-middleware");
const sass = require("gulp-sass")

//转存
function copyFile() {
  return src([
    "../**/*",
    "!../{www,www/**}",
    "!../{nodejs,nodejs/**}",
    "!../{gapu,gapu/**}",
  ]).pipe(dest("../www"));
}



//监听转存
function autoCopyFile() {
  return watch(
    [
      "../**/*",
      "!../{www,www/**}",
      "!../{nodejs,nodejs/**}",
      "!../{gapu,gapu/**}",
    ],
    copyFile
  );
}
//合并插件 压缩 重命名 转存
function concatCss() {
  return src(["../css/*", "!../css/reset.css"])
    .pipe(concat("index.css"))
    .pipe(dest("../cssEX"));
}

//ES6转5
function szfFile() {
  return src("src/c.js")
    .pipe(
      babel({
        presets: ["@babel/env"],
      })
    )
    .pipe(dest("./src"));
}

function serverFn() {
  connect.server({
    port: 81, //设置端口
    root: "../WWW", //设置根目录
  });
}

//sass
function stcFn() {
  return src("../sass/*.scss")
    .pipe(sass().on("error", sass.logError))
    .pipe(dest("../cssEX"))
}

function autoStcFn() {
  return watch("../sass/*", stcFn)
}

exports.autoStc = autoStcFn;
exports.copyFile = copyFile;
exports.autoCopyFile = autoCopyFile;
exports.concatCss = concatCss;
exports.szfFile = szfFile;
exports.server = serverFn;
exports.autoUpdata = parallel(serverFn, autoCopyFile);
exports.autoUpdataCss = parallel(autoStcFn, autoCopyFile);